Skip to content

Reduce projections during unification#20730

Closed
Tragicus wants to merge 2 commits intorocq-prover:masterfrom
Tragicus:reduce-projs
Closed

Reduce projections during unification#20730
Tragicus wants to merge 2 commits intorocq-prover:masterfrom
Tragicus:reduce-projs

Conversation

@Tragicus
Copy link
Contributor

@Tragicus Tragicus commented Jun 9, 2025

Unifying structures is very slow (see e.g. math-comp/math-comp#1365). So whenever we see a projection, we can try to reduce it. This also simplifies the Canonical Structures procedure (e.g. gets rid of the "keys" and restores the previous reduction strategy avoids backtracking in the reduction strategy).

Fixes / closes #????

  • Added / updated test-suite.
  • Added changelog.
  • Added / updated documentation.
    • Documented any new / changed user messages.
    • Updated documented syntax by running make doc_gram_rsts.
  • Opened overlay pull requests.

Overlays:

@Tragicus Tragicus requested a review from a team as a code owner June 9, 2025 11:12
@coqbot-app coqbot-app bot added the needs: full CI The latest GitLab pipeline that ran was a light CI. Say "@coqbot run full ci" to get a full CI. label Jun 9, 2025
@Tragicus
Copy link
Contributor Author

May I ask for a bench?

@gares
Copy link
Member

gares commented Jun 17, 2025

@coqbot bench now

@coqbot-app
Copy link
Contributor

coqbot-app bot commented Jun 17, 2025

🏁 Bench results:

┌─────────────────────────────────────┬───────────────────────┬─────────────────────────────────────┬─────────────────────────┐
│                                     │     user time [s]     │          CPU instructions           │  max resident mem [KB]  │
│                                     │                       │                                     │                         │
│            package_name             │  NEW     OLD    PDIFF │      NEW            OLD       PDIFF │   NEW      OLD    PDIFF │
├─────────────────────────────────────┼───────────────────────┼─────────────────────────────────────┼─────────────────────────┤
│                            coq-core │   2.83    2.89  -2.08 │   19859613403    19815046858   0.22 │   94808    94928  -0.13 │
│                           rocq-core │   6.26    6.35  -1.42 │   39081038318    39094874904  -0.04 │  440676   442180  -0.34 │
│                       coq-fiat-core │  58.02   58.62  -1.02 │  354603317813   354585239758   0.01 │  488108   485612   0.51 │
│                           rocq-elpi │  12.70   12.82  -0.94 │   91251071951    91271356871  -0.02 │  485216   480652   0.95 │
│                         coq-coqutil │  45.08   45.42  -0.75 │  284736373043   284735732442   0.00 │  562504   562000   0.09 │
│                        coq-coqprime │  51.74   52.05  -0.60 │  356454720146   356409800532   0.01 │  799780   806456  -0.83 │
│                      rocq-equations │   8.78    8.83  -0.57 │   60700621680    60569521820   0.22 │  400240   400728  -0.12 │
│                rocq-metarocq-common │  42.34   42.56  -0.52 │  273205396090   273241860190  -0.01 │  926692   927556  -0.09 │
│                        coq-rewriter │ 336.32  337.99  -0.49 │ 2522575186794  2521213618719   0.05 │ 1307888  1301860   0.46 │
│ coq-neural-net-interp-computed-lite │ 231.95  232.90  -0.41 │ 2245615556729  2245092590536   0.02 │  894472   884496   1.13 │
│                         rocq-stdlib │ 444.85  446.47  -0.36 │ 1576323344291  1576869489809  -0.03 │  616272   618556  -0.37 │
│                        rocq-bignums │  30.26   30.36  -0.33 │  194045804542   194048223646  -0.00 │  483628   482772   0.18 │
│              rocq-metarocq-template │  83.16   83.43  -0.32 │  576578632147   576608860439  -0.01 │  994060   994160  -0.01 │
│          coq-performance-tests-lite │ 898.42  900.11  -0.19 │ 7256444946978  7261940215733  -0.08 │ 1940168  1940380  -0.01 │
│                        coq-compcert │ 311.23  311.22   0.00 │ 2033672704798  2033487259045   0.01 │ 1151280  1144100   0.63 │
│                    coq-math-classes │  86.73   86.52   0.24 │  531816666353   531800302402   0.00 │  512492   512032   0.09 │
│         coq-rewriter-perf-SuperFast │ 477.91  476.00   0.40 │ 3740262039237  3740807164486  -0.01 │ 1216452  1214692   0.14 │
│          rocq-metarocq-translations │  16.57   16.48   0.55 │  117490636264   117501527844  -0.01 │  761600   768836  -0.94 │
│               coq-engine-bench-lite │ 125.57  124.74   0.67 │  940746155414   937172392453   0.38 │ 1099760  1099816  -0.01 │
│                        rocq-runtime │  74.13   73.55   0.79 │  535436822337   535315952767   0.02 │  490032   489516   0.11 │
│                 rocq-metarocq-utils │  23.23   22.99   1.04 │  151615700151   151804197433  -0.12 │  584228   581524   0.46 │
│                        coq-bedrock2 │ 388.19  347.63  11.67 │ 3370709553697  2898362874970  16.30 │ 1107220   871880  26.99 │
└─────────────────────────────────────┴───────────────────────┴─────────────────────────────────────┴─────────────────────────┘

INFO: failed to install
coq-hott (in NEW)
rocq-mathcomp-ssreflect (dependency install failed in NEW)
coq-corn (in NEW)
rocq-metarocq-pcuic (in NEW)
coq-color (in NEW)
coq-fiat-parsers (in NEW)
coq-fiat-crypto-with-bedrock (in NEW)
coq-unimath (in NEW)
coq-iris-examples (dependency install failed in NEW)
coq-verdi (in NEW)
coq-vst (in NEW)
coq-category-theory (in NEW)

rocq-mathcomp-fingroup (dependency rocq-mathcomp-ssreflect failed)
rocq-mathcomp-algebra (dependency rocq-mathcomp-ssreflect failed)
rocq-mathcomp-solvable (dependency rocq-mathcomp-ssreflect failed)
rocq-mathcomp-field (dependency rocq-mathcomp-ssreflect failed)
rocq-mathcomp-character (dependency rocq-mathcomp-ssreflect failed)
coq-mathcomp-odd-order (dependency rocq-mathcomp-ssreflect failed)
coq-mathcomp-analysis (dependency rocq-mathcomp-ssreflect failed)
rocq-metarocq-safechecker (dependency rocq-metarocq-pcuic failed)
rocq-metarocq-erasure (dependency rocq-metarocq-pcuic failed)
coq-coquelicot (dependency rocq-mathcomp-ssreflect failed)
coq-verdi-raft (dependency coq-verdi failed)
coq-fourcolor (dependency rocq-mathcomp-ssreflect failed)

🐢 Top 25 slow downs
┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│                                                TOP 25 SLOW DOWNS                                                 │
│                                                                                                                  │
│   OLD      NEW    DIFF      %DIFF     Ln                FILE                                                     │
├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│   0.0609   31.3  31.2867  51367.11%    369  coq-bedrock2/bedrock2/src/bedrock2Examples/LAN9250.v.html            │
│   0.0246   7.15   7.1227  28991.81%    368  coq-bedrock2/bedrock2/src/bedrock2Examples/LAN9250.v.html            │
│  0.00502  0.797   0.7918  15761.05%    369  coq-bedrock2/bedrock2/src/bedrock2Examples/LAN9250.v.html            │
│     17.4   18.1   0.7081      4.07%     31  coq-engine-bench-lite/coq/PerformanceDemos/pattern.v.html            │
│     5.78   6.47   0.6814     11.78%    628  coq-bedrock2/bedrock2/src/bedrock2Examples/LAN9250.v.html            │
│     2.33   2.90   0.5732     24.65%    607  rocq-stdlib/theories/Zmod/ZmodBase.v.html                            │
│     45.3   45.9   0.5057      1.12%    118  coq-bedrock2/bedrock2/src/bedrock2Examples/full_mul.v.html           │
│     3.09   3.55   0.4580     14.83%    196  rocq-stdlib/theories/ZArith/ZModOffset.v.html                        │
│     1.22   1.58   0.3592     29.43%   1142  rocq-stdlib/theories/FSets/FMapAVL.v.html                            │
│     1.44   1.77   0.3323     23.05%    313  rocq-stdlib/theories/Strings/Byte.v.html                             │
│    0.266  0.589   0.3239    121.97%     12  rocq-stdlib/theories/MSets/MSets.v.html                              │
│     23.7   24.1   0.3163      1.33%    558  coq-bedrock2/bedrock2/src/bedrock2Examples/insertionsort.v.html      │
│     1.14   1.42   0.2795     24.61%    207  rocq-stdlib/theories/setoid_ring/Ncring_tac.v.html                   │
│     9.95   10.2   0.2765      2.78%    214  coq-engine-bench-lite/coq/PerformanceDemos/one_step_reduction.v.html │
│     9.83   10.1   0.2718      2.77%    325  coq-engine-bench-lite/coq/PerformanceDemos/one_step_reduction.v.html │
│    0.118  0.351   0.2338    198.85%     12  rocq-stdlib/theories/Reals/Abstract/ConstructiveAbs.v.html           │
│     1.02   1.25   0.2258     22.15%    572  rocq-stdlib/theories/MSets/MSetAVL.v.html                            │
│    0.357  0.583   0.2257     63.22%     13  rocq-stdlib/theories/Numbers/DecimalFacts.v.html                     │
│    0.200  0.423   0.2235    111.98%     14  rocq-stdlib/theories/Numbers/Cyclic/Int63/Uint63.v.html              │
│ 0.000564  0.207   0.2062  36553.37%  16790  coq-coqprime/src/Coqprime/examples/BasePrimes.v.html                 │
│    0.245  0.450   0.2051     83.61%     34  rocq-stdlib/theories/Logic/SetoidChoice.v.html                       │
│     17.7   17.9   0.2012      1.14%    670  coq-performance-tests-lite/src/Nia.v.html                            │
│    0.231  0.412   0.1813     78.64%    131  rocq-stdlib/theories/MSets/MSetProperties.v.html                     │
│    0.359  0.528   0.1693     47.18%    443  rocq-stdlib/theories/Reals/Abstract/ConstructiveLimits.v.html        │
│     1.09   1.25   0.1623     14.92%    408  rocq-stdlib/theories/MSets/MSetAVL.v.html                            │
└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
🐇 Top 25 speed ups
┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│                                                            TOP 25 SPEED UPS                                                             │
│                                                                                                                                         │
│  OLD     NEW      DIFF     %DIFF    Ln                     FILE                                                                         │
├─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│   200       199  -0.8396   -0.42%      8  coq-neural-net-interp-computed-lite/theories/MaxOfTwoNumbersSimpler/Computed/AllLogits.v.html │
│  1.46     0.779  -0.6822  -46.68%    559  coq-bedrock2/bedrock2/src/bedrock2Examples/LAN9250.v.html                                     │
│  65.9      65.4  -0.5738   -0.87%    609  coq-bedrock2/bedrock2/src/bedrock2Examples/lightbulb.v.html                                   │
│   100      99.7  -0.4369   -0.44%    968  coq-performance-tests-lite/src/fiat_crypto_via_setoid_rewrite_standalone.v.html               │
│  99.9      99.6  -0.3630   -0.36%    999  coq-performance-tests-lite/src/fiat_crypto_via_setoid_rewrite_standalone.v.html               │
│  1.50      1.22  -0.2720  -18.17%     75  rocq-stdlib/theories/Numbers/HexadecimalString.v.html                                         │
│ 0.468     0.210  -0.2577  -55.07%   1982  rocq-stdlib/theories/FSets/FMapFacts.v.html                                                   │
│ 0.619     0.366  -0.2536  -40.94%    208  rocq-stdlib/theories/setoid_ring/Ncring_tac.v.html                                            │
│ 0.950     0.698  -0.2525  -26.57%     41  rocq-stdlib/theories/ZArith/Zdiv_facts.v.html                                                 │
│ 0.461     0.213  -0.2481  -53.82%     17  rocq-stdlib/theories/micromega/Env.v.html                                                     │
│ 0.466     0.218  -0.2480  -53.24%     11  rocq-stdlib/theories/micromega/ZifyComparison.v.html                                          │
│  1.16     0.925  -0.2390  -20.54%   2109  rocq-stdlib/theories/FSets/FMapFacts.v.html                                                   │
│ 0.616     0.379  -0.2375  -38.53%     10  rocq-stdlib/theories/extraction/ExtrHaskellZNum.v.html                                        │
│ 0.201  0.000527  -0.2002  -99.74%  16783  coq-coqprime/src/Coqprime/examples/BasePrimes.v.html                                          │
│  22.1      21.9  -0.1990   -0.90%    651  rocq-stdlib/theories/Zmod/ZmodBase.v.html                                                     │
│  39.0      38.8  -0.1968   -0.50%    236  coq-rewriter/src/Rewriter/Rewriter/Examples/PerfTesting/LiftLetsMap.v.html                    │
│ 0.516     0.330  -0.1862  -36.10%     11  rocq-stdlib/theories/setoid_ring/Rings_Z.v.html                                               │
│ 0.958     0.774  -0.1836  -19.16%    813  rocq-stdlib/theories/MSets/MSetRBT.v.html                                                     │
│ 0.402     0.225  -0.1775  -44.15%    759  rocq-stdlib/theories/MSets/MSetRBT.v.html                                                     │
│ 0.371     0.200  -0.1714  -46.17%    172  rocq-stdlib/theories/FSets/FSetFacts.v.html                                                   │
│ 0.788     0.618  -0.1693  -21.49%    816  rocq-stdlib/theories/MSets/MSetRBT.v.html                                                     │
│  38.2      38.0  -0.1664   -0.44%    224  coq-performance-tests-lite/PerformanceExperiments/rewrite_lift_lets_map.v.html                │
│ 0.714     0.555  -0.1588  -22.23%    160  rocq-stdlib/theories/Numbers/HexadecimalNat.v.html                                            │
│ 0.576     0.418  -0.1585  -27.50%    705  rocq-stdlib/theories/Numbers/HexadecimalFacts.v.html                                          │
│ 0.260     0.109  -0.1511  -58.00%     25  rocq-stdlib/theories/Logic/ClassicalChoice.v.html                                             │
└─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘

@SkySkimmer SkySkimmer marked this pull request as draft June 19, 2025 10:46
Tragicus added 2 commits June 19, 2025 15:03
When encountering a projection, we weak-head reduce its subject. If we obtain a
constructor, we reduce the projection immediately (without backtracking).
Otherwise and if the reduced subject is not ground, we try solving the
canonical structure problem after refolding the other term to its state
at the start of the unification.
@Tragicus Tragicus marked this pull request as ready for review June 19, 2025 14:07
@Tragicus Tragicus marked this pull request as draft June 19, 2025 14:11
@github-actions github-actions bot added the needs: rebase Should be rebased on the latest master to solve conflicts or have a newer CI run. label Sep 22, 2025
@coqbot-app
Copy link
Contributor

coqbot-app bot commented Oct 22, 2025

The "needs: rebase" label was set more than 30 days ago. If the PR is not rebased in 30 days, it will be automatically closed.

@coqbot-app coqbot-app bot added the stale This PR will be closed unless it is rebased. label Oct 22, 2025
@coqbot-app
Copy link
Contributor

coqbot-app bot commented Nov 21, 2025

This PR was not rebased after 30 days despite the warning, it is now closed.

@coqbot-app coqbot-app bot closed this Nov 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs: full CI The latest GitLab pipeline that ran was a light CI. Say "@coqbot run full ci" to get a full CI. needs: rebase Should be rebased on the latest master to solve conflicts or have a newer CI run. stale This PR will be closed unless it is rebased.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants